package com.icim.core.service.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.icim.core.service.IAlarmSenderService;
import com.icim.core.tx.Amssend.AmssenderI;
import com.icim.util.HttpClientUtil;
import com.icim.util.XmlConvertUtil;

@Service
public class AlarmSenderService implements IAlarmSenderService {

    private Logger logger = Logger.getLogger(AlarmSenderService.class);

    @Resource
    HttpClientUtil httpClientUtil;

    public void sendAlarm(String mailText, String mailToAdds) {
        String subject = "资料外送系统出现错误";
        sendToAMS(mailText, subject, mailToAdds);
    }

    private void sendToAMS(String mailText, String subject, String mailToAdds) {
        AmssenderI inTrx = new AmssenderI();
        inTrx.setMail_subject(subject);
        inTrx.setMail_text(mailText);
        inTrx.setTrx_id("AMSSENDER");
        inTrx.setType_id("I");
        inTrx.setAction_flg("M");
        inTrx.setMail_toAdds(mailToAdds);
        String outMesg = httpClientUtil.postHttp(XmlConvertUtil.obj2Xml(inTrx, "transaction"));

        if (outMesg.contains("0000000")) {
            logger.info(outMesg);
        } else {
            logger.error(outMesg);
        }
    }

}
